import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:units/components/tool-btn.dart';
import 'package:units/conversion/data.dart';
import 'package:units/conversion/conversion.dart';
import 'package:units/global.dart';
import 'package:units/iconfont.dart';

class HomePage extends StatefulWidget {
  HomePage({Key key}) : super(key: key);
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  void initState() {
    SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        decoration: BoxDecoration(
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors: [
              Global.primaryColor,
              Global.primaryColor.withOpacity(1),
            ],
          ),
        ),
        child: Wrap(
          alignment: WrapAlignment.center,
          runAlignment: WrapAlignment.center,
          runSpacing: 20,
          children: [
            ToolButton(
              icon: IconFont.shujutubiao05,
              text: '功率换算',
              onTap: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => PowerPage(
                      name: '功率',
                      unitData: UnitsData.gonglvData,
                    ),
                  ),
                );
              },
            ),
            ToolButton(
              icon: IconFont.changdu,
              text: '长度换算',
              onTap: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => PowerPage(
                      name: '长度',
                      unitData: UnitsData.changduData,
                    ),
                  ),
                );
              },
            ),
            ToolButton(
              icon: IconFont.zhongliang,
              text: '重量换算',
              onTap: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => PowerPage(
                      name: '重量',
                      unitData: UnitsData.zhongliangData,
                    ),
                  ),
                );
              },
            ),
            ToolButton(
              icon: IconFont.tiji,
              text: '体积换算',
              onTap: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => PowerPage(
                      name: '体积',
                      unitData: UnitsData.tijiData,
                    ),
                  ),
                );
              },
            ),
            ToolButton(
              icon: IconFont.lujing,
              text: '面积换算',
              onTap: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => PowerPage(
                      name: '面积',
                      unitData: UnitsData.mianjiData,
                    ),
                  ),
                );
              },
            ),
            ToolButton(
              icon: IconFont.nengliang,
              text: '热量换算',
              onTap: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => PowerPage(
                      name: '热量',
                      unitData: UnitsData.reliangData,
                    ),
                  ),
                );
              },
            ),
          ],
        ),
      ),
    );
  }
}
